using UnityEngine;

//追击状态
public class EnemyChaseState : EnemyState
{
    public EnemyChaseState(EnemyFSM manager, string animationName) : base(manager, animationName) { }

    public override  void OnEnter()
    {
        base.OnEnter();
        parameter.currentSpeed = parameter.chaseSpeed;
    }

    public override void OnUpdate()
    {
        base.OnUpdate();
        // 如果被击中了，转换到受击状态
        if (parameter.isHurt)
        {
            manager.TransitionState(StateType.Hit);
        }

        // 如果检测到攻击范围内有目标，则转换到攻击状态
        if (parameter.isAttack)
        {
            manager.TransitionState(StateType.MeleeAttack);
        }

        //如果在悬崖或者触碰墙壁，转换到空闲状态
        if(!parameter.check.isTouchGround || parameter.check.isTouchWall){
            manager.TransitionState(StateType.Idle);
        }

        // 转换到空闲状态
        if (!parameter.isChase)
        {
            manager.TransitionState(StateType.Idle);
        }
    }

    
    public override void OnFixedUpdate()
    {
        base.OnFixedUpdate();
        manager.FlipTo(parameter.target);    // 面向目标
        Move();
    }

    public override void OnExit()
    {
        base.OnExit();
    }

}

